﻿/// <reference path="StringBuilder.js" />
/// <reference path="Extensions/RegExp.js" />

function Cookies()
{
}
Cookies.Add = function Add(name, value, hours)
{
	var sb = new StringBuilder();
	sb.Append(name);
	sb.Append("=");
	sb.Append(value);

	if (typeof (hours) == "number")
	{
		var date = new Date();
		date.setTime(date.getTime() + (hours * 60 * 60 * 1000));
		sb.Append("; expires=");
		sb.Append(date.toGMTString());
	}
	sb.Append(";");
	sb.Append(" path=/");
	document.cookie = sb.toString();
}
Cookies.Get = function Get(name)
{
	var allCookies = document.cookie;
	var rgx = new RegExp("(?:(?:^)|(?:;\\s?))" + RegExp.Escape(name) + "=([^;]+)");
	var match = rgx.exec(allCookies);
	if (match == null || match[1] == null || match[1] == "")
		return null;
	return match[1];
}
Cookies.Erase = function Erase(name)
{
	Cookies.Add(name, "", -1);
}